Constructor for self_organizing_map
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
type(kohonen_layer_parameters), | dimension(:) | :: | training_parameters |
A |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=NUMCHAR), | public, | parameter | :: | fname | = | 'create_som' |
A character variable with the name of the function |
integer, | public | :: | ierr | ||||
integer, | public | :: | nx | ||||
integer, | public | :: | ny | ||||
integer, | public | :: | nz | ||||
integer, | public | :: | ix | ||||
integer, | public | :: | iy | ||||
integer, | public | :: | iz | ||||
integer, | public | :: | nvar1 | ||||
integer, | public | :: | nvar2 | ||||
integer, | public | :: | seed | ||||
integer, | public | :: | current_index | ||||
integer, | public | :: | nepoch | ||||
integer, | public | :: | i | ||||
integer, | public | :: | j | ||||
real(kind=wp), | public, | allocatable | :: | input(:,:) | |||
character(len=NUMCHAR), | public | :: | base_message | ||||
character(len=NUMCHAR), | public | :: | message |
subroutine create_som(kohonen_map,training_parameters) !======================================================================================== !! Constructor for self_organizing_map character(len=NUMCHAR),parameter :: fname = 'create_som' !! A character variable with the name of the function class(self_organizing_map) :: kohonen_map !! A `self_organizing_map` object type(kohonen_layer_parameters),dimension(:) :: training_parameters !! A `kohonen_layer_parameters` object integer :: ierr,nx,ny,nz,ix,iy,iz,nvar1,nvar2,seed,current_index,nepoch integer :: i,j real(kind=wp),allocatable :: input(:,:) character(len=NUMCHAR) :: base_message,message ! base_message=trim(kohonen_map%class_name)//'_'//trim(fname)//'_ERROR'; ! kohonen_map%parameters=training_parameters(1); nx=training_parameters(1)%number_nodes_nx; ny=training_parameters(1)%number_nodes_ny; nz=training_parameters(1)%number_nodes_nz; nvar1=training_parameters(1)%number_variables1; nvar2=training_parameters(1)%number_variables2; nepoch=training_parameters(1)%number_epochs; write(*,*) 'Create= ',nx,ny,nz,nvar1,nvar2,nepoch; allocate(kohonen_map%grid(nx,ny,nz),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for grid array'; call error_stop(message); endif ! allocate(kohonen_map%grid_pattern_index(nx,ny,nz),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for grid_pattern_index array'; call error_stop(message); endif ! allocate(input(nvar1,nvar2),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for input array'; call error_stop(message); endif ! allocate(kohonen_map%number_patterns(nx,ny,nz),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for number_patterns array'; call error_stop(message); endif ! allocate(kohonen_map%cells_index(training_parameters(1)%number_patterns,3),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for cell_index array'; call error_stop(message); endif ! kohonen_map%number_patterns=0; kohonen_map%cells_index=0; allocate(kohonen_map%u_matrix(2*nx-1,2*ny-1,2*nz-1),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for u_matrix array'; call error_stop(message); endif kohonen_map%u_matrix=0.0_wp; ! allocate(kohonen_map%distance(nx*ny,nx*ny),stat=ierr); if(ierr /= 0) then message = trim(base_message)//'_allocating memory for distance array'; call error_stop(message); endif kohonen_map%distance=0.0_wp; ! allocate(kohonen_map%cells_distances(nx*ny*nz,nx*ny*nz),stat=ierr); kohonen_map%cells_distances=0.0d0; allocate(kohonen_map%coordinates(nx*ny*nz,3),stat=ierr); kohonen_map%coordinates=0.0d0; allocate(kohonen_map%distortion(nepoch),stat=ierr); kohonen_map%distortion=0.0d0; ! call kohonen_map%factory%create_distance(training_parameters(1)%distance_type,& kohonen_map%distance_function); ! kohonen_map%seed=training_parameters(1)%random_seed_(1); call kohonen_map%rnumber_grator%create(kohonen_map%seed); ! do i=1,nvar1; ! do j=1,nvar2; ! input(i,j)=kohonen_map%rnumber_grator%generate(); ! !write(*,*) 'input= ',input(i,j); ! enddo ! enddo ! write(*,*) 'SOM: Initializing grid...',kohonen_map%seed; do iz=1,nz; do iy=1,ny; do ix=1,nx; !write(*,*) 'creating ',ix,iy,iz call kohonen_map%create_random_sample(input); call kohonen_map%grid(ix,iy,iz)%create(input); current_index=position2index(ix,iy,iz,nx,ny); call calculate_coordinates(current_index,ix,iy,iz,nx,ny,nz,& kohonen_map%coordinates,training_parameters(1)%node_type); enddo!ix enddo !iy enddo !iz deallocate(input); ! call calculate_distance_matrix(kohonen_map%coordinates,kohonen_map%cells_distances,& training_parameters(1)%node_type,training_parameters(1)%toroidal_grid); write(*,*) 'SOM: Initializing grid...OK'; ! end subroutine create_som